package com.example.demo.lock;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Phone {

    Lock lock = new ReentrantLock();


    public void send(){
        lock.lock();
        try {
            System.out.println(Thread.currentThread().getName()+"-> send");
            Thread.sleep(2000);
        }catch (Exception e){

        }finally {
            lock.unlock();
        }
    }

    public void call(){
        lock.lock();
        try {
            System.out.println(Thread.currentThread().getName()+"-> call");
        }catch (Exception e){

        }finally {
            lock.unlock();
        }
    }

}

class TestPhone{

    public static void main(String[] args) {
        Phone p = new Phone();

        new Thread(p::send,"A").start();


        new Thread(p::call,"B").start();



    }
}